<template>
  <div class="app-container">
    <div class="schema-list">
      <el-carousel height="200px" :autoplay="false">
        <el-carousel-item >
          <div class="schema-basic-info">
            <div class="schema-detail">
              <div class="app-item">
                <div class="app-img">
                  <img src="@/assets/images/jindie.png">
                </div>
                <div class="app-info">
                  <div class="app-name">金蝶云星空</div>
                  <div class="app-vers">类型: 通用</div>
                </div>
              </div>
              <div class="exchange-icon-box">
                <svg-icon icon-class="exchange" style="height: 38px;width: 87px;"/>
              </div>
              <div class="app-item">
                <div class="app-img">
                  <img src="@/assets/images/serialNum.jpg">
                </div>
                <div class="app-info">
                  <div class="app-name">序列号追溯系统</div>
                  <div class="app-vers">类型: 标准</div>
                </div>
              </div>
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['interfaceConfig:sceneConfig:add']"
        >自定义场景</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['interfaceConfig:sceneConfig:remove']"
        >移除场景</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="sceneConfigList" border @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center">
        <template slot-scope="scope">
          {{( queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}
        </template>
      </el-table-column>
      <el-table-column label="集成场景" align="center" >
        <template #default="{row}">
          <span>{{row.sysObjName1}}-{{row.sysObjName2}}</span>
        </template>
      </el-table-column>
      <el-table-column label="系统1对象名称" align="center" prop="sysObjName1" />
      <el-table-column label="集成方向" align="center" prop="integrationDirection" >
        <template #default="{row}">
          <img v-show="row.integrationDirection === '02'" src="">
          <img v-show="row.integrationDirection === '01'" src="">
        </template>
      </el-table-column>
      <el-table-column label="系统2对象名称" align="center" prop="sysObjName2" />
      <el-table-column label="是否支持调度" align="center" prop="isSupportedSchedule">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.service_yes_no" :value="scope.row.isSupportedSchedule"/>
        </template>
      </el-table-column>
      <el-table-column label="是否启用" align="center" prop="isEnable">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.isEnable"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            style="color: red"
            @click="handleDelete(scope.row)"
            v-hasPermi="['interfaceConfig:sceneConfig:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            @click="settingFieldMapping(scope.row)"
            v-hasPermi="['interfaceConfig:sceneConfig:fieldMapping']"
          >设置字段映射</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>
<script>
import { listSceneConfig, getSceneConfig, delSceneConfig, addSceneConfig, updateSceneConfig } from "@/api/interfaceConfig/sceneConfig/sceneConfig";

export default {
  name: 'SceneConfig',
  dicts: ['service_yes_no', 'sys_normal_disable'],
  data() {
    return {
// 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 集成场景配置表格数据
      sceneConfigList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  mounted() {
    this.getList();
  },
  methods: {
    /** 查询集成场景配置列表 */
    getList() {
      this.loading = true;
      listSceneConfig(this.queryParams).then(response => {
        this.sceneConfigList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sysObjId1: null,
        sysObjId2: null,
        isSupportedSchedule: null,
        isEnable: null,
        integrationDirection: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push('/sceneConfig/addSceneConfig')
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSceneConfig(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改集成场景配置";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSceneConfig(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSceneConfig(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除集成场景配置编号为"' + ids + '"的数据项？').then(function() {
        return delSceneConfig(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    settingFieldMapping(row) {
      this.$router.push({
        path: '/sceneConfig/sceneFieldSetting',
        query: {
          id: row.id
        }
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('interfaceConfig/sceneConfig/export', {
        ...this.queryParams
      }, `sceneConfig_${new Date().getTime()}.xlsx`)
    }
  }
}

</script>
<style lang="scss" scoped>
::v-deep .el-carousel__container{
  height: 150px !important;
  .carousel-box .el-carousel .el-carousel__indicators {
    display: none;
  }
  &:hover > .el-carousel__arrow--left,.el-carousel__arrow--right{
    display: none;
  }
}
.schema-basic-info {
  width: 80%;
  margin: 0 auto;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  .schema-detail {
    width: 100%;
    margin: 10px 0 10px;
    display: flex;
    justify-content: space-around;
    -webkit-box-align: center;
    align-items: center;
    .app-item {
      width: 260px;
      height: 100px;
      background: linear-gradient(122deg, #65b1ff 0%, #4a79ff 100%);
      border-radius: 4px;
      display: flex;
      -webkit-box-align: center;
      align-items: center;
      .app-img {
        width: 76px;
        height: 76px;
        margin-left: 15px;
        border-radius: 50%;
        background: #fff;
        display: flex;
        -ms-flex-negative: 0;
        flex-shrink: 0;
        -webkit-box-pack: center;
        justify-content: center;
        -webkit-box-align: center;
        align-items: center;
        overflow: hidden;
        img {
          width: 100%;
        }
      }
      .app-info {
        margin-left: 18px;
        padding-right: 10px;
        word-break: break-all;
        color: #fff;
        .app-vers {
          font-size: 14px;
          margin: 5px 0;
        }
      }
    }
    .exchange-icon-box {
      text-align: center;
      cursor: default;
    }
  }
}
</style>
